import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)


const store = new Vuex.Store({
	state: {
		url:'http://8.129.179.105:10036',
		url1:'http://8.129.179.105:10016',
		serketUrl:'ws://47.106.231.209:10014/ws',
		navbg:'#1878ff',
		navcolor:'#fff',
		vars:false,
		user:false,
		collection:[],//关注列表
	},
	mutations: {
		init(state){
			// console.log(state.url + '/api/shequuser/mycenter/dealeracclist?ftoken=' + state.user.token)
			if(state.user){
				// uni.request({
				// 	// url: this.$store.state.url+'http://47.113.81.106:10016/api/GWDataShow/GetDataShowList',
				// 	url:state.url + '/api/dealeraccount/dealeracclist?ftoken=' + state.user.token,
				// 	method: 'POST',
				// 	success: res => {
				// 		console.log(res)
				// 		// for(var i in res.data.data){
				// 		// 	res.data.data[i].checked = false;
				// 		// 	state.shipan.push(res.data.data[i])
				// 		// }
				// 		state.shipan = res.data.data;
				// 	},
				// 	fail: res => {
				// 		console.log(res);
				// 	}
				// });
				// store.commit('getcollection');
				
				
			}
		},
		getcollection(state){
			uni.request({
				// url: this.$store.state.url+'http://47.113.81.106:10016/api/GWDataShow/GetDataShowList',
				url:state.url + '/api/shequuser/mycenter/myfocus?ftoken='+state.user.token,
				method: 'POST',
				success: res => {
					if(res.data.code !== 200) return;
					if(res.data.data){
						state.collection = res.data.data;
					}
				},
				
				fail: res => {
					console.log(res);
				}
			});
		},
		setuser(state, data) {//登录
			state.user = data;
			uni.setStorageSync('userdata',JSON.stringify(data));//缓存用户信息
		},
		removeuser(state,type) {//退出登录
			state.user = false;
			uni.removeStorageSync('userdata');
			if(!type){
				uni.navigateTo({
				url: '/pages/login/login'
			});
			}
			
		},
		setcol(state,arr,obj){
			// state.collection = arr;
			// uni.setStorageSync('collection',JSON.stringify(arr));//缓存用户信息
		}
	},
    getters:{
       
    },
	actions: {
		
	}
})

export default store
